﻿<%@ Page Language="C#" AutoEventWireup="true" Theme="Default" CodeFile="LayoutMode.aspx.cs"
    Inherits="LayoutMode" %>

<%@ Register Src="TopFixedMenu.ascx" TagName="TopFixedMenu" TagPrefix="menu" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    
    <menu:topfixedmenu id="TopFixedMenu1"  runat="server" />
    <form id="form1" runat="server">
    <asp:Literal ID="ltrContent" runat="server"></asp:Literal>
    <div style="position: absolute; background-color: White; font-size: 12px; z-index: 100000;
        padding: 3px 8px 3px 8px; border: solid 1px black; display: none;" id="menu_Layout">
        <a href="#">Add Module</a>
    </div>
    <div id="dialogAddModule" style="display: none;">
        <table style="text-align: left;" width="100%">
            <tr>
                <td width="30%">
                    Module:
                </td>
                <td width="70%">
                    <asp:DropDownList ID="DDLModule" onchange="GetSubModules(this);" Width="100%" runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    Sub Module:
                </td>
                <td>
                    <asp:DropDownList ID="DDLSubModule" Width="100%" runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    <div id="DivModuleSubModuleLoading" style="display: none;">
                        Loading...</div>
                </td>
            </tr>
        </table>
    </div>
    <div id="dialogEditContent" style="display: none;">
        <div class="EditModuleSettingsLoading">
            Loading...</div>
        <iframe id="dialogEditContentIframe" allowtransparency="true" style="display: none;"
            onload='EditModuleFrameLoad();' name="dialogEditContentIframe" width="100%" height="100%"
            frameborder="0"></iframe>
    </div>
    <script language="javascript" type="text/javascript">
        var $menu = $("#menu_Layout"), pos;
        function EditModuleFrameLoad() {
            $("#dialogEditContent .EditModuleSettingsLoading").css("display", "none");
            $("#dialogEditContentIframe").css("display", "");
        }
        function showMenu(objThis) {

            //get the position of the placeholder element
            pos = $(objThis).offset();
            var PageId = $(objThis).children(".hidPageId")[0].value;
            var SectionId = $(objThis).children(".hidSectionId")[0].value;


            //show the menu directly over the placeholder
            $menu.css({ "left": (pos.left) + "px", "top": pos.top + "px" }).show();
            $menu.select("a").unbind("click");
            $menu.select("a").click(function () {
                OpenAddModuleDialog(PageId, SectionId);
                $(this).css("display", "none"); ;
            });
        }
        function GetSubModules(objThis) {
            $("#DDLSubModule").html("<option value='0'>Select</option>");
            $("#DivModuleSubModuleLoading").css("display", "");
            $.ajax({
                url: '<%=ResolveClientUrl("~/Process.aspx")%>',
                type: "POST",
                contentType: "application/x-www-form-urlencoded;charset=UTF8",
                dataType: 'json',
                data: "funcation=GetSubModules&ModuleId=" + objThis.value,
                success: function (data, textStatus) {
                    for (i = 0; i < data.length; i++) {
                        $("#DDLSubModule").append($("<option></option>").val(data[i].Id).html(data[i].Name));
                    }
                    if (data.length == 0)
                        $("#DDLSubModule").parent().parent().css("display", "none");
                    else
                        $("#DDLSubModule").parent().parent().css("display", "");
                    $("#DivModuleSubModuleLoading").css("display", "none");
                }
            });
        }
        function OpenAddModuleDialog(PageId, SectionId) {

            $("#dialogAddModule").dialog({
                modal: true,
                title: 'Add Module',
                buttons: {
                    Ok: function () {
                        $.ajax({
                            url: '<%=ResolveClientUrl("~/Process.aspx")%>',
                            type: "POST",
                            contentType: "application/x-www-form-urlencoded;charset=UTF8",
                            dataType: 'html',
                            data: "funcation=ADDMODULE&ModuleId=" + $("#DDLModule").val() + "&SubModuleId=" + $("#DDLSubModule").val() + "&PageId=" + PageId + "&SectionId=" + SectionId,
                            success: callback
                        });
                        $(this).dialog('close');
                    },
                    Cancel: function () {
                        $(this).dialog('close');
                    }
                }
            });
        }
        function OpenEditModuleDialog(ModuleCode, id, pageId, url, width, height) {
            $menu.css("display", "none");
            $("#dialogEditContentIframe").css("display", "none");
            $("#dialogEditContent .EditModuleSettingsLoading").css("display", "block");
            $("#dialogEditContentIframe").attr("src", url);
            $("#dialogEditContent").dialog({
                modal: true,
                title: 'Edit Module',
                width: width,
                height: height,
                buttons: {
                    "Remove Module": function () {
                        $.ajax({
                            url: '<%=ResolveClientUrl("~/Process.aspx")%>',
                            type: "POST",
                            contentType: "application/x-www-form-urlencoded;charset=UTF8",
                            dataType: 'html',
                            data: "funcation=RemoveModule&PageModuleId=" + pageId,
                            success: function (data, textStatus) {
                                closeDialogWindow();
                            }
                        });
                    },
                    Save: function () {
                        window.frames['dialogEditContentIframe'].document.getElementById('btnSave').click();
                    },
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
            });
        }
        function callback(data, textStatus) {
            document.location.href = document.location.href.replace('#', '');
        }
        function closeDialogWindow() {
            $("#dialogEditContent").dialog('close');
            document.location.href = document.location.href.replace('#', '');
        }
        function openWindow(anchor, options) {
            $("#dialogEditContent").dialog('close');
            var args = '';

            if (typeof (options) == 'undefined') { var options = new Object(); }
            if (typeof (options.name) == 'undefined') { options.name = 'win' + Math.round(Math.random() * 100000); }

            if (typeof (options.height) != 'undefined' && typeof (options.fullscreen) == 'undefined') {
                args += "height=" + options.height + ",";
            }

            if (typeof (options.width) != 'undefined' && typeof (options.fullscreen) == 'undefined') {
                args += "width=" + options.width + ",";
            }

            if (typeof (options.fullscreen) != 'undefined') {
                args += "width=" + screen.availWidth + ",";
                args += "height=" + screen.availHeight + ",";
            }

            if (typeof (options.center) == 'undefined') {
                options.x = 0;
                options.y = 0;
                args += "screenx=" + options.x + ",";
                args += "screeny=" + options.y + ",";
                args += "left=" + options.x + ",";
                args += "top=" + options.y + ",";
            }

            if (typeof (options.center) != 'undefined' && typeof (options.fullscreen) == 'undefined') {
                options.y = Math.floor((screen.availHeight - (options.height || screen.height)) / 2) - (screen.height - screen.availHeight);
                options.x = Math.floor((screen.availWidth - (options.width || screen.width)) / 2) - (screen.width - screen.availWidth);
                args += "screenx=" + options.x + ",";
                args += "screeny=" + options.y + ",";
                args += "left=" + options.x + ",";
                args += "top=" + options.y + ",";
            }

            if (typeof (options.scrollbars) != 'undefined') { args += "scrollbars=1,"; }
            if (typeof (options.menubar) != 'undefined') { args += "menubar=1,"; }
            if (typeof (options.locationbar) != 'undefined') { args += "location=1,"; }
            if (typeof (options.resizable) != 'undefined') { args += "resizable=1,"; }

            var win = window.open(anchor, options.name, args);
            return false;

        }
    </script>
    <script type="text/javascript">
        $(".topFixedMenu").jixedbar({
            showOnTop: true,
            transparent: true,
            opacity: 0.5,
            slideSpeed: "slow",
            roundedCorners: false,
            roundedButtons: false,
            menuFadeSpeed: "slow",
            tooltipFadeSpeed: "fast",
            tooltipFadeOpacity: 0.5
        });
    </script>
    </form>
</body>
</html>
